﻿<UserControl x:Class="QuanLyKho.ucNhapKho"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
             xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
             xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" 
             xmlns:local="clr-namespace:QuanLyKho"
             xmlns:collections="clr-namespace:System.Collections;assembly=mscorlib"
             Loaded="UserControl_Loaded">
    <UserControl.Resources>
        <Style TargetType="Label">
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="Margin" Value="5,0,0,0" />
        </Style>
        <Style TargetType="dxe:DateEdit">
            <Setter Property="Margin" Value="2,2" />
        </Style>
        <Style TargetType="dxe:TextEdit">
            <Setter Property="Margin" Value="2,2" />
        </Style>
        <Style TargetType="dxe:ComboBoxEdit">
            <Setter Property="Margin" Value="2,2" />
        </Style>
    </UserControl.Resources>
    <UserControl.CommandBindings>
        <CommandBinding Command="{x:Static local:ucNhapKho.FocusHomeCommand}" Executed="FocusHomeCommandExecute" CanExecute="FocusHomeCommandCanExecute" />
    </UserControl.CommandBindings>
    <UserControl.InputBindings>
        <KeyBinding Command="{x:Static local:ucNhapKho.FocusHomeCommand}" Key="G" Modifiers="Alt" />
    </UserControl.InputBindings>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="123"></RowDefinition>
            <RowDefinition Height="200*"></RowDefinition>
            <RowDefinition Height="42"></RowDefinition>
        </Grid.RowDefinitions>
        <GroupBox Header="Thông tin phiếu nhập" Margin="2 2 2 2">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="28"></RowDefinition>
                    <RowDefinition Height="28"></RowDefinition>
                    <RowDefinition Height="28"></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="95"></ColumnDefinition>
                    <ColumnDefinition Width="130*"></ColumnDefinition>
                    <ColumnDefinition Width="85"></ColumnDefinition>
                    <ColumnDefinition Width="120*"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <Label Content="Số Phiếu Nhập:"></Label>
                <dxe:TextEdit Name="txtIdPhieuNhap" Grid.Column="1" IsReadOnly="True" 
                      HorizontalContentAlignment="Center" FontSize="15" FontWeight="Bold" 
                      Foreground="Red" Background="Aqua"/>
                <Label Content="Nhà Phân Phối:" Grid.Row="1"></Label>
                <dxe:ComboBoxEdit Name="cboNhaPhanPhoi" 
                          IsTextEditable="True"
                          Grid.Column="1" Grid.Row="1" TabIndex="1" 
                          AutoComplete="True"
                          IsCaseSensitiveSearch="False" 
                          InvalidValueBehavior="AllowLeaveEditor" 
                          Validate="cboNhaPhanPhoi_Validate" 
                          EditValueChanging="cboNhaPhanPhoi_EditValueChanging"/>
                <Label Content="Số Hóa Đơn:" Grid.Column="2"></Label>
                <dxe:TextEdit Name="txtSoHoaDon" Grid.Column="3" TabIndex="2" KeyDown="txtSoHoaDon_KeyDown" KeyUp="txtSoHoaDon_KeyUp" />
                <Label Content="Ngày Nhập:" Grid.Row="1" Grid.Column="2"></Label>
                <dxe:DateEdit Grid.Column="3" Grid.Row="1" TabIndex="3" Name="deNgayNhap" 
                      Mask="dd/MM/yyyy" MaskAutoComplete="Optimistic" 
                      InvalidValueBehavior="AllowLeaveEditor"
                      MaskType="DateTimeAdvancingCaret" DisplayFormatString="dd/MM/yyyy"
                      EditValueChanging="deNgayNhap_EditValueChanging" 
                      Validate="deNgayNhap_Validate"/>
                <Label Content="Chiết khấu:" Grid.Row="2"></Label>
                <dxe:SpinEdit Name="txtChietKhau" Grid.Row="2" Grid.Column="1" TabIndex="4" Margin="2,2,107,2" MinValue="0" MaxValue="100" 
                              EditValueChanging="txtChietKhau_EditValueChanging"
                              EditValueChanged="txtChietKhau_EditValueChanged"/>
                <Label Content="Thiết Lập Nợ:" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Right" Margin="2,0,20,0"></Label>
                <dxe:CheckEdit Name="chkLaPhieuNo" Grid.Row="2" Grid.Column="1" Margin="2,2" TabIndex="5" IsChecked="False" HorizontalAlignment="Right"
                               Checked="chkLaPhieuNo_Checked" Unchecked="chkLaPhieuNo_Unchecked"/>
                <Label Content="Lý Do Nợ:" Grid.Row="2" Grid.Column="2"></Label>
                <dxe:TextEdit Name="txtLyDoNo" Grid.Row="2" Grid.Column="3" TabIndex="6" KeyUp="txtLyDoNo_KeyUp" KeyDown="txtLyDoNo_KeyDown"/>
            </Grid>
        </GroupBox>
        <dxg:GridControl Name="gridChiTiet" Grid.Row="1" AutoExpandAllGroups="True">
            <dxg:GridControl.Columns>
                <dxg:GridColumn FieldName="MaThuoc" Header="Mã Vật Tư" Width="60" Name="colMaThuoc" Validate="colMaThuoc_Validate"/>
                <dxg:GridColumn FieldName="Dm_Thuoc.TenThuoc" Header="Tên vật tư" Width="130" Name="colTenThuoc"/>
                <dxg:GridColumn FieldName="TenHamLuong" Header="HL" Width="60" ReadOnly="True"/>
                <dxg:GridColumn FieldName="TenDonViTinh" Header="ĐVT" Width="50" ReadOnly="True"/>
                <dxg:GridColumn FieldName="SoLuong" Header="Số lượng" Width="40" Name="colSoLuong" Validate="colSoluong_Validate">
                    <dxg:GridColumn.EditSettings>
                        <dxe:TextEditSettings MaskType="Numeric"/>
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn FieldName="HanDung" Header="Hạn dùng" Width="60" Name="colHanDung" Validate="colHanDung_Validate">
                    <dxg:GridColumn.EditSettings>
                        <dxe:DateEditSettings MaskType="DateTimeAdvancingCaret" Mask="dd/MM/yyyy" MaskUseAsDisplayFormat="True" DisplayFormat="dd/MM/yyyy"/>
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn FieldName="GiaNhap" Header="Giá nhập" Width="50" Name="colGiaNhap" Validate="colGiaNhap_Validate">
                    <dxg:GridColumn.EditSettings>
                        <dxe:TextEditSettings MaskType="Numeric" Mask="c0" MaskUseAsDisplayFormat="True" MaskCulture="Vietnamese (Vietnam)"/>
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn FieldName="GiaXuat" Header="Giá bán" Width="50" Name="colGiaXuat" Validate="colGiaXuat_Validate">
                    <dxg:GridColumn.EditSettings>
                        <dxe:TextEditSettings MaskType="Numeric" Mask="c0" MaskUseAsDisplayFormat="True" MaskCulture="Vietnamese (Vietnam)"/>
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn FieldName="ChietKhau" Header="Chiết khấu" Visible="False" ReadOnly="True"/>
                <dxg:GridColumn FieldName="ThanhTien" Header="Thành tiền (Nhập)" ReadOnly="True" UnboundType="Decimal" UnboundExpression="((100 - [ChietKhau]) * [GiaNhap]/100) * [SoLuong]" Width="60">
                    <dxg:GridColumn.EditSettings>
                        <dxe:TextEditSettings MaskType="Numeric" Mask="c0" MaskUseAsDisplayFormat="True" MaskCulture="Vietnamese (Vietnam)" />
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn FieldName="SoLo" Header="Số lô" Width="50" Name="colSoLo" Validate="colSoLo_Validate">
                    <dxg:GridColumn.EditSettings>
                        <dxe:TextEditSettings />
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
            </dxg:GridControl.Columns>
            <dxg:GridControl.TotalSummary>
                <dxg:GridSummaryItem FieldName="ThanhTien" SummaryType="Sum" DisplayFormat=" {0:n0} đ"/>
            </dxg:GridControl.TotalSummary>
            <dxg:GridControl.View>
                <dxg:TableView Name="tbvChiTiet" TabIndex="7" AllowColumnFiltering="True" ShowAutoFilterRow="True" ShowTotalSummary="True"
                               ShowGroupPanel="False" AutoWidth="True" NewItemRowPosition="Top" AllowGrouping="True"
                               PreviewKeyDown="tbvChiTiet_PreviewKeyDown"
                               CellValueChanged="tbvChiTiet_CellValueChanged"
                               FocusedRowChanged="tbvChiTiet_FocusedRowChanged"
                               ValidateRow="tbvChiTiet_ValidateRow" 
                               InvalidRowException="tbvChiTiet_InvalidRowException" 
                               InitNewRow="tbvChiTiet_InitNewRow"
                               PreviewMouseLeftButtonDown="tbvChiTiet_PreviewMouseLeftButtonDown"
                               RowUpdated="tbvChiTiet_RowUpdated"
                               />
            </dxg:GridControl.View>
        </dxg:GridControl>
        <dxb:BarManager Name="barManagerButton" Grid.Row="2" CreateStandardLayout="True">
            <dxb:BarManager.Items>
                <!--Regular bar items-->
                <dxb:BarButtonItem x:Name="btnThemMoi" Content="_Thêm mới" BarItemDisplayMode="ContentAndGlyph"  
                                   LargeGlyph ="Images/Icons/new-32x32.png" ItemClick="btnThemMoi_ItemClick" />
                <dxb:BarButtonItem x:Name="btnLuu" Content="_Lưu" BarItemDisplayMode="ContentAndGlyph"  
                                   LargeGlyph ="Images/Icons/save.png" ItemClick="btnLuu_ItemClick" />
                <dxb:BarButtonItem x:Name="btnXoa" Content="_Xóa" BarItemDisplayMode="ContentAndGlyph" 
                                   LargeGlyph ="Images/Icons/deletered.png" ItemClick="btnXoa_ItemClick" />
                <dxb:BarButtonItem x:Name="btnHuyBo" Content="_Hủy bỏ" BarItemDisplayMode="ContentAndGlyph" 
                                   LargeGlyph ="Images/Icons/undo.png" ItemClick="btnHuyBo_ItemClick" />
                <dxb:BarButtonItem x:Name="btnDong" Content="Đó_ng" BarItemDisplayMode="ContentAndGlyph" 
                                   LargeGlyph ="Images/Icons/logout.png" ItemClick="btnDong_ItemClick" />
            </dxb:BarManager.Items>
            <!--Create two bars-->
            <dxb:BarManager.Bars>
                <dxb:Bar>
                    <dxb:Bar.ItemLinks>
                        <dxb:BarItemLink BarItemName="btnThemMoi"/>
                        <dxb:BarItemLink BarItemName="btnLuu"/>
                        <dxb:BarItemLink BarItemName="btnXoa"/>
                        <dxb:BarItemLink BarItemName="btnHuyBo"/>
                        <dxb:BarItemLink BarItemName="btnDong"/>
                    </dxb:Bar.ItemLinks>
                </dxb:Bar>
            </dxb:BarManager.Bars>
        </dxb:BarManager>
    </Grid>
</UserControl>
